from django import forms
from .models import Comment,sonComment


class CommentForm(forms.ModelForm):
    text = forms.CharField(
                required=True,label="内容",
                error_messages={'required':'沉默有时会产生尴尬。','max_length':'想说的太多了，请给我发邮件吧。','min_length':'就这就这？'},
                max_length=300,min_length=2,widget=forms.Textarea(attrs={'placeholder':'发表以下意见吧'}))
    name = forms.CharField(
                required=True,
                label="名字",
                error_messages={'required':'忘记写名字啦！','max_length':'给爷爬！',},
                max_length=300)
    class Meta:
        model = Comment
        fields = ['name', 'email', 'url', 'text','qqnumber','picurl','platform','browser']

    def clean_text(self):
        message = self.cleaned_data['text']
        if "fuck" in message:
            raise forms.ValidationError('你说你🐎呢')
        return message
    def clean_name(self):
        name = self.cleaned_data['name']
        if "admin" in name or "Admin" in name:
            raise forms.ValidationError('阿这，这不合适吧')
        return name

class sonCommentForm(forms.ModelForm):
    text = forms.CharField(
                required=True,label="内容",
                error_messages={'required':'沉默有时会产生尴尬。','max_length':'想说的太多了，请给我发邮件吧。','min_length':'就这就这？'},
                max_length=300,min_length=2,widget=forms.Textarea(attrs={'placeholder':'发表以下意见吧'}))
    name = forms.CharField(
                required=True,label="名字",
                error_messages={'required':'忘记写名字啦！','max_length':'给爷爬！',},
                max_length=300)
    class Meta:
        model = sonComment
        fields = ['name', 'email', 'url', 'text','qqnumber','picurl','platform','browser']

    def clean_text(self):
        message = self.cleaned_data['text']
        if "fuck" in message:
            raise forms.ValidationError('你说你🐎呢')
        return message
    def clean_name(self):
        name = self.cleaned_data['name']
        if "admin" in name or "Admin" in name:
            raise forms.ValidationError('阿这，这不合适吧')
        return name